/*
 * Copyright (c) 2017-present, CV4J Contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cv4j.rxcv4j;

import com.cv4j.uitl.Log;

/**
 * KCV4J
 *
 * @since 2021-05-17
 */
public class KCV4J {
    /**
     * kcv4j
     */
    private KCV4J() {
    }

    /**
     * cv4j
     *
     * @param wrapper 包装器
     */
    public static void cv4j(Wrapper wrapper) {
        render(wrapper);
    }

    /**
     * 渲染
     *
     * @param wrap 包装
     */
    private static void render(Wrapper wrap) {
        if (wrap.bitmap != null) {
            RxImageData.bitmap(wrap.bitmap)
                .dialog(wrap.dialog)
                .addFilter(wrap.filter)
                .isUseCache(wrap.useCache)
                .into(wrap.imageView);
        } else if (wrap.cv4jImage != null) {
            RxImageData.image(wrap.cv4jImage)
                .dialog(wrap.dialog)
                .addFilter(wrap.filter)
                .isUseCache(wrap.useCache)
                .into(wrap.imageView);
        } else if (wrap.bytes != null) {
            RxImageData.bytes(wrap.bytes)
                .dialog(wrap.dialog)
                .addFilter(wrap.filter)
                .isUseCache(wrap.useCache)
                .into(wrap.imageView);
        } else {
            // do nothing
            Log.debug("tag"," do nothing");
        }
    }
}
